package dao

import (
	"context"
	"github.com/ego-component/egorm"
)

type PromptTemplate struct {
	ID        int64  `gorm:"primaryKey;autoIncrement;comment:主键"`
	PromptKey string `gorm:"type:varchar(255);uniqueIndex:idx_prompt_key;comment:唯一键"`
	Template  string `gorm:"type:text;not null;comment:模板内容"`
	Ctime     int64  `gorm:"column:ctime;comment:创建时间戳（毫秒）"`
	Utime     int64  `gorm:"column:utime;comment:更新时间戳（毫秒）"`
}
type PromptDAO interface {
	FindPromptByKey(ctx context.Context, key string) (PromptTemplate, error)
}

type promptDAO struct {
	db *egorm.Component
}

func NewPromptDAO(db *egorm.Component) PromptDAO {
	return &promptDAO{
		db: db,
	}
}

func (p *promptDAO) FindPromptByKey(ctx context.Context, key string) (PromptTemplate, error) {
	var tem PromptTemplate
	err := p.db.WithContext(ctx).
		Model(&PromptTemplate{}).
		Where("prompt_key = ?", key).First(&tem).Error
	return tem, err
}
